/*
 * Copyright the original author or authors.
 * 
 * Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *	  http://www.mozilla.org/MPL/MPL-1.1.html
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.milib.display {
	import com.googlecode.milib.base.MLBaseClass;

	/**
	 * @author Marek Brun
	 */
	public class TwoSidesAndMidSmashableModel extends MLBaseClass {
		
		public var setupSide0Length : Number;
		public var setupSide1Length : Number;
		public var setupLength : Number;
		public var setupPos : Number;
		public var setupMidMinLength : Number;
		
		// side1 - mid - side2
		
		public function TwoSidesAndMidSmashableModel(){
			setupSide0Length=0;
			setupSide1Length=0;
			setupLength=0;
			setupPos=0;
			setupMidMinLength=0;
		}
		
		public function setupSidesLength(length:Number):void {
			setupSide0Length=length/2;
			setupSide1Length=length/2;
		}
		
		public function getSidesLength():Number {
			return getSide0Length()+getSide1Length();
		}
		
		public function getSide1IniPos():Number {
			return setupLength-getSide1Length();
		}
		
		public function getScrollingAreaLength():Number {
			return setupLength-getSidesLength();
		}
		
		public function getMidLength():Number {
			var sidesLength:Number=setupSide0Length+setupSide1Length;
			if(sidesLength>setupLength){
				return 0;
			}else{
				return setupLength-sidesLength;
			}
		}
		
		public function getMidIniPos():Number {
			return setupPos+getSide0Length();
		}
		
		public function getSide0Length():Number {
			var sidesLength:Number=setupSide0Length+setupSide1Length;
			var scrollingArea:Number=setupLength-sidesLength;
			if(scrollingArea<0){
				return Math.max(setupSide0Length+scrollingArea/2, 0);
			}else{
				return setupSide0Length;
			}
		}
		
		public function getSide1Length():Number {
			var sidesLength:Number=setupSide0Length+setupSide1Length;
			var scrollingArea:Number=setupLength-sidesLength;
			if(scrollingArea<0){
				return Math.max(setupSide1Length+scrollingArea/2, 0);
			}else{
				return setupSide1Length;
			}
		}
		
	}
}
